/*
 * @Descripttion: GGB
 * @version: 1.0
 * @Author: GGB
 * @Date: 2021-08-17 16:46:11
 * @LastEditors: GGB
 * @LastEditTime: 2021-08-18 07:14:11
 */
import 'package:flutter/material.dart';
import 'package:flutter_data_center/controller/wristband_controller.dart';
import 'package:get/get.dart';
import './components/wristband_count.dart';
import './components/wristband_list.dart';
import './components/wristband_menu.dart';

class WristbandScreen extends StatefulWidget {
  const WristbandScreen({Key key}) : super(key: key);
  static String routeName = "/wristband";

  @override
  _WristbandScreenState createState() => _WristbandScreenState();
}

class _WristbandScreenState extends State<WristbandScreen> {
  final keyWidget = GlobalKey();
  WristbandController _wristbandController = Get.put(WristbandController());
  double height = 0;
  void calculateSizeAndPosition() =>
      WidgetsBinding.instance.addPostFrameCallback((_) {
        final RenderBox box =
            keyWidget.currentContext.findRenderObject(); // 包含widget的绘制信息
        setState(() {
          height = box.size.height + 90;
        });
      });
  @override
  void initState() {
    super.initState();
    calculateSizeAndPosition();
    // 发起数据请求
    _wristbandController.getWristBandTotal();
    _wristbandController.getList();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Colors.transparent,
        elevation: 0,
      ),
      extendBodyBehindAppBar: true,
      body: SafeArea(
        child: SingleChildScrollView(
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 30),
            child: Column(
              children: [
                Column(
                  key: keyWidget,
                  children: [
                    WristbandCount(),
                    WristbandMenu(),
                  ],
                ),
                Container(
                  height: MediaQuery.of(context).size.height - height,
                  child: WristbandList(),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
